From a4368a73a50a62bf5c8195a678cc542c0c164f9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Wed, 12 Oct 2016 19:46:23 +0200 Subject: [PATCH] widget: Remove gtk_widget_reparent --- docs/reference/gtk/gtk4-sections.txt | 1 - gtk/gtkwidget.c | 126 --------------------------- gtk/gtkwidget.h | 3 - tests/testgtk.c | 34 +++++--- tests/testlist2.c | 7 +- 5 files changed, 25 insertions(+), 146 deletions(-) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 185d4d9ab6..8148ffcb6b 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -5050,7 +5050,6 @@ gtk_widget_list_accel_closures gtk_widget_can_activate_accel gtk_widget_event gtk_widget_activate -gtk_widget_reparent gtk_widget_intersect gtk_widget_is_focus gtk_widget_grab_focus diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index ca6be0c0bc..140cd5eb36 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -7184,132 +7184,6 @@ gtk_widget_activate (GtkWidget *widget) return FALSE; } -static void -gtk_widget_reparent_subwindows (GtkWidget *widget, - GdkWindow *new_window) -{ - GtkWidgetPrivate *priv = widget->priv; - - if (!_gtk_widget_get_has_window (widget)) - { - GList *children = gdk_window_get_children (priv->window); - GList *tmp_list; - - for (tmp_list = children; tmp_list; tmp_list = tmp_list->next) - { - GdkWindow *window = tmp_list->data; - gpointer child; - - gdk_window_get_user_data (window, &child); - while (child && child != widget) - child = ((GtkWidget*) child)->priv->parent; - - if (child) - gdk_window_reparent (window, new_window, 0, 0); - } - - g_list_free (children); - } - else - { - GdkWindow *parent; - GList *tmp_list, *children; - - parent = gdk_window_get_parent (priv->window); - - if (parent == NULL) - gdk_window_reparent (priv->window, new_window, 0, 0); - else - { - children = gdk_window_get_children (parent); - - for (tmp_list = children; tmp_list; tmp_list = tmp_list->next) - { - GdkWindow *window = tmp_list->data; - gpointer child; - - gdk_window_get_user_data (window, &child); - - if (child == widget) - gdk_window_reparent (window, new_window, 0, 0); - } - - g_list_free (children); - } - } -} - -static void -gtk_widget_reparent_fixup_child (GtkWidget *widget, - gpointer client_data) -{ - GtkWidgetPrivate *priv = widget->priv; - - g_assert (client_data != NULL); - - if (!_gtk_widget_get_has_window (widget)) - { - if (priv->window) - g_object_unref (priv->window); - priv->window = (GdkWindow*) client_data; - if (priv->window) - g_object_ref (priv->window); - - if (GTK_IS_CONTAINER (widget)) - gtk_container_forall (GTK_CONTAINER (widget), - gtk_widget_reparent_fixup_child, - client_data); - } -} - -/** - * gtk_widget_reparent: - * @widget: a #GtkWidget - * @new_parent: a #GtkContainer to move the widget into - * - * Moves a widget from one #GtkContainer to another, handling reference - * count issues to avoid destroying the widget. - * - * Deprecated: 3.14: Use gtk_container_remove() and gtk_container_add(). - **/ -void -gtk_widget_reparent (GtkWidget *widget, - GtkWidget *new_parent) -{ - GtkWidgetPrivate *priv; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (GTK_IS_CONTAINER (new_parent)); - priv = widget->priv; - g_return_if_fail (priv->parent != NULL); - - if (priv->parent != new_parent) - { - /* First try to see if we can get away without unrealizing - * the widget as we reparent it. if so we set a flag so - * that gtk_widget_unparent doesn't unrealize widget - */ - if (_gtk_widget_get_realized (widget) && _gtk_widget_get_realized (new_parent)) - priv->in_reparent = TRUE; - - g_object_ref (widget); - gtk_container_remove (GTK_CONTAINER (priv->parent), widget); - gtk_container_add (GTK_CONTAINER (new_parent), widget); - g_object_unref (widget); - - if (priv->in_reparent) - { - priv->in_reparent = FALSE; - - gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget)); - gtk_widget_reparent_fixup_child (widget, - gtk_widget_get_parent_window (widget)); - } - - g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_PARENT]); - } -} - /** * gtk_widget_intersect: * @widget: a #GtkWidget diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 4c5ac48f71..8d926e44bf 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -738,9 +738,6 @@ gboolean gtk_widget_send_focus_change (GtkWidget *widget, GDK_AVAILABLE_IN_ALL gboolean gtk_widget_activate (GtkWidget *widget); -GDK_DEPRECATED_IN_3_14 -void gtk_widget_reparent (GtkWidget *widget, - GtkWidget *new_parent); GDK_AVAILABLE_IN_ALL gboolean gtk_widget_intersect (GtkWidget *widget, const GdkRectangle *area, diff --git a/tests/testgtk.c b/tests/testgtk.c index bded479ed6..d493bba2e8 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -1739,9 +1739,10 @@ reparent_label (GtkWidget *widget, label = g_object_get_data (G_OBJECT (widget), "user_data"); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_widget_reparent (label, new_parent); -G_GNUC_END_IGNORE_DEPRECATIONS + g_object_ref (label); + gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (widget)), label); + gtk_container_add (GTK_CONTAINER (new_parent), label); + g_object_unref (label); } static void @@ -3271,10 +3272,11 @@ static gulong sw_destroyed_handler = 0; static gboolean scrolled_windows_delete_cb (GtkWidget *widget, GdkEventAny *event, GtkWidget *scrollwin) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_widget_reparent (scrollwin, sw_parent); -G_GNUC_END_IGNORE_DEPRECATIONS - + g_object_ref (scrollwin); + gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (scrollwin)), scrollwin); + gtk_container_add (GTK_CONTAINER (sw_parent), scrollwin); + g_object_unref (scrollwin); + g_signal_handler_disconnect (sw_parent, sw_destroyed_handler); sw_float_parent = NULL; sw_parent = NULL; @@ -3304,9 +3306,12 @@ scrolled_windows_remove (GtkWidget *dialog, gint response, GtkWidget *scrollwin) if (sw_parent) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_widget_reparent (scrollwin, sw_parent); -G_GNUC_END_IGNORE_DEPRECATIONS + g_object_ref (scrollwin); + gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (scrollwin)), scrollwin); + gtk_container_add (GTK_CONTAINER (sw_parent), scrollwin); + g_object_unref (scrollwin); + + gtk_widget_destroy (sw_float_parent); g_signal_handler_disconnect (sw_parent, sw_destroyed_handler); @@ -3323,9 +3328,12 @@ G_GNUC_END_IGNORE_DEPRECATIONS gtk_window_set_default_size (GTK_WINDOW (sw_float_parent), 200, 200); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_widget_reparent (scrollwin, sw_float_parent); -G_GNUC_END_IGNORE_DEPRECATIONS + g_object_ref (scrollwin); + gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (scrollwin)), scrollwin); + gtk_container_add (GTK_CONTAINER (sw_float_parent), scrollwin); + g_object_unref (scrollwin); + + gtk_widget_show (sw_float_parent); sw_destroyed_handler = diff --git a/tests/testlist2.c b/tests/testlist2.c index 1f0b2aa97d..5f0a09e2a5 100644 --- a/tests/testlist2.c +++ b/tests/testlist2.c @@ -20,9 +20,10 @@ remove_this_row (GtkButton *button, GtkWidget *child) revealer = gtk_revealer_new (); gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE); gtk_widget_show (revealer); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_widget_reparent (child, revealer); -G_GNUC_END_IGNORE_DEPRECATIONS + g_object_ref (child); + gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (child)), child); + gtk_container_add (GTK_CONTAINER (revealer), child); + g_object_unref (child); gtk_container_add (GTK_CONTAINER (row), revealer); g_signal_connect (revealer, "notify::child-revealed", G_CALLBACK (row_unrevealed), NULL); -- 2.30.2